﻿<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
﻿<!DOCTYPE html>
<html lang="zh_CN">
<head>
   <%@ include file="../common/header.jsp"%>
</head>
<body>

<div class="container " style="margin-top: 20px">
   <%@ include file="../common/top.jsp"%>

    <div class="row">
        <div class="col-sm-3">
            <!-- <#assign menu="systemDictionary"%> -->
           <%@ include file="../common/menu.jsp"%>
        </div>
        <div class="col-sm-9">
            <div class="row">
                <div class="col-sm-12">
                    <h1 class="page-head-line">字典目录管理</h1>
                </div>
            </div>
            <!-- 高级查询 -->
            <form class="form-inline" id="searchForm" action="/systemDictionary/list.do" method="post">
                <input type="hidden" name="currentPage" id="currentPage" value="1">
                <a role="button" class="btn btn-success inputBtn">
                    <span class="glyphicon glyphicon-plus"></span> 添加
                </a>
            </form>

            <table class="table table-striped table-hover" >
                <tr>
                    <th>编号</th>
                    <th>字典标题</th>
                    <th>字典编码</th>
                    <th>字典介绍</th>
                    <th>操作</th>
                </tr>
                <!-- <#list pageInfo.list as entity> -->
                <c:forEach var="entity" items="${pageInfo.list}" varStatus="status">
                    <tr>
                        <td>${status.index + 1}</td>
                        <td>${entity.title}</td>
                        <td>${entity.sn}</td>
                        <td>${entity.intro}</td>
                        <td>
                            <a role="button" class="btn btn-info btn-xs inputBtn" data-json='${entity.json}'>
                                <span class="glyphicon glyphicon-pencil"></span> 编辑
                            </a>
                            <a role="button" data-url="/systemDictionary/delete.do?id=${entity.id}"
                               class="btn btn-danger btn-xs deleteBtn">
                                <span class="glyphicon glyphicon-trash"></span> 删除
                            </a>
                        </td>
                    </tr>
                    </c:forEach>
                <!-- </#list> -->
            </table>

            <!--分页-->
           <%@ include file="../common/page.jsp" %>
        </div>
    </div>
</div>

<!-- 字典目录编辑的模态框 -->
<div class="modal fade" id="systemDictionaryModal" tabindex="-1" role="dialog"
     aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <!--模态框的头部-->
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="systemDictionaryModal">编辑</h4>
            </div>
            <!--模态框的正文-->
            <div class="modal-body">
                <form class="form-horizontal" action="/systemDictionary/saveOrUpdate.do" method="post" id="editForm">
                    <input type="hidden" name="id">
                    <div class="form-group" >
                        <label class="col-sm-4 control-label">字典标题：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="title" placeholder="请输入字典标题">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">字典编码：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="sn" placeholder="请输入字典编码">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">字典简介：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="intro" placeholder="请输入字典简介">
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary systemDictionarySubmitBtn">保存</button>
            </div>
        </div>
    </div>
</div>

<script>
    $(function () {
        //找到所有的inputBtn类绑定点击事件
        $(".inputBtn").click(function () {
            //1:先清空模态框数据
            $("#editForm input").val("");
            //2:尝试拿到当前按钮上的JSON数据
            //拿到到data-json
            var json = $(this).data("json"); //去当前对象上的自定义属性的数据
            //3:只有编辑按钮才要回显数据
            if (json) {
                //把数据回显到模态框中
                $("#editForm input[name='id']").val(json.id);
                $("#editForm input[name='title']").val(json.title);
                $("#editForm input[name='sn']").val(json.sn);
                $("#editForm input[name='intro']").val(json.intro);
            }
            //4:弹出模态框
            $("#systemDictionaryModal").modal("show");
        });

        //异步提交表单
        $("#editForm").ajaxForm(function (data) {
            doSuccess();
        });

        //给表单按钮绑定点击事件,提交表单
        $(".systemDictionarySubmitBtn").click(function () {
            $("#editForm").submit();
        });
    });
</script>
</body>
</html>